Skip to main content

All Questions

3votes
4answers
600views

Why is "dependency injection" ok, but not "the opposite of preserve whole object (pass required parameters only)"?

According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
wcminipgasker2023's user avatar
0votes
0answers
205views

How to handle dependency injection in a library to avoid frequent breaking changes?

Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
srk's user avatar
  • 127
0votes
3answers
328views

How to choose between these different options for communicating between objects?

I have a few objects that should communicate between each other. I also want to have my code unit tested. I am questioning how I should handle their communication: Should I make one instantiate the ...
ianmandarini's user avatar
-1votes
3answers
876views

Factory needs list of available objects. Should it be static or not?

I have a list of IReader that I read at the beginning of my program. Later on I need ReaderFactory to get appropriate IReader based on Extensions it can use. The problem is the factory needs to know ...
FCin's user avatar
  • 522
20votes
5answers
7kviews

What are the benefits of dependency injection in cases where almost everyone needs access to a common data structure?

There are plenty of reasons why globals are evil in OOP. If the number or size of the objects needing sharing is too large to be efficiently passed around in function parameters, usually everyone ...
vsz's user avatar
  • 1,496
6votes
1answer
4kviews

PHP: Injecting the same database connection into multiple objects

Suppose that there are two classes that define objects of vastly different function such that in the datastore, the information they require is divided into two separate databases. For example, the ...
concat's user avatar
2votes
1answer
242views

Injection, strategies and OO

I'm working on refactoring a project. The business logic looks very much like using the Strategy pattern would be very beneficial, because depending on the values of three properties (let's say age, ...
user3748908's user avatar
-1votes
1answer
512views

Multiple method calls in the constructor and dependency injection

I was asked to refactor some almost ureadable spaghetti code into object-oriented architecture. I have some doubts regarding a class that I designed. Here is the class' skeleton: require_once 'inc/...
luqo33's user avatar
4votes
2answers
392views

Sharing state with dependencies - Object-Oriented Design

Suppose that I define two interfaces below: public interface IReader { void Read(string bookName); } public interface IWriter { void Write(string bookName); } Now I want to implement IReader ...
Mert Akcakaya's user avatar
13votes
6answers
3kviews

Questioning one of the arguments for dependency injection frameworks: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, you ...
oberlies's user avatar
17votes
2answers
31kviews

Factory Pattern and/or Dependency Injection? [duplicate]

I understand the concept and can use both the Factory Pattern and Dependency Injection, however they seem a little at odds with each other conceptually. Is it a case of using one over the other? Or ...
Samuel Hawksby-Robinson's user avatar

close